/**
 * 
 */
package com.phone580.app.untilty;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

/**
 * 对话框工具
 * @author xianpunan
 * @date     2012-4-10
 */
public class AlertUtil {
	
	public static ProgressDialog showProgress(Context context, String message) {
		 ProgressDialog dialog = new ProgressDialog(context);
//         dialog.setTitle("Indeterminate");
         dialog.setMessage(message);
         dialog.setIndeterminate(true);
         dialog.setCancelable(true);
         return dialog;
	}

    /**
     * Show Alert Dialog
     * @param context
     * @param titleId
     * @param messageId
     */
    public static void showAlert(Context context, int titleId, String message) {
        Dialog dlg = new AlertDialog.Builder(context)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle(titleId)
            .setPositiveButton(android.R.string.ok, null)
            .setMessage(message)
            .create();
        
        dlg.show();
    }
    
    public static void showAlert(Context context, int titleId, String message,  OnClickListener positive) {
        Dialog dlg = new AlertDialog.Builder(context)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle(titleId)
            .setPositiveButton(android.R.string.ok, positive)
            .setMessage(message)
            .create();
        
        dlg.show();
    }
    
    public static void showAlert(Context context, int titleId, String message, OnClickListener positive, OnClickListener navigate) {
        Dialog dlg = new AlertDialog.Builder(context)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle(titleId)
            .setPositiveButton(android.R.string.ok, positive)
            .setNegativeButton(android.R.string.cancel, navigate)
            .setMessage(message)
            .create();
        
        dlg.show();
    }
    
    public static void showAlert(Context context, int titleId, String message,String ok, OnClickListener positive,String cancel, OnClickListener navigate) {
        Dialog dlg = new AlertDialog.Builder(context)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle(titleId)
            .setPositiveButton(ok, positive)
            .setNegativeButton(cancel, navigate)
            .setMessage(message)
            .create();
        
        dlg.show();
    }
    
    /**
     * 创建列表对话框
     * @param context
     * @param title
     * @param items
     * @param listener
     * @return
     */
    public static Dialog showListDialog(Context context, String title, String[] items, DialogInterface.OnClickListener listener) {
    	 return new AlertDialog.Builder(context)
         .setTitle(title)
         .setItems(items, listener)
         .create();
    }
}
